package com.xjlsoft.weather.service.impl;

import com.xjlsoft.weather.common.util.DataUtil;
import com.xjlsoft.weather.common.util.DateUtil;
import com.xjlsoft.weather.dto.DataAvgDto;
import com.xjlsoft.weather.entity.AerosolAvg;
import com.xjlsoft.weather.entity.AerosolData;
import com.xjlsoft.weather.entity.GroundAvg;
import com.xjlsoft.weather.entity.GroundData;
import com.xjlsoft.weather.entity.RadiationAvg;
import com.xjlsoft.weather.entity.RadiationData;
import com.xjlsoft.weather.enums.AvgFlagEnum;
import com.xjlsoft.weather.enums.DataTypeEnum;
import com.xjlsoft.weather.mapper.RadiationAvgMapper;
import com.xjlsoft.weather.mapper.RadiationDataMapper;
import com.xjlsoft.weather.service.RadiationAvgService;
import com.xjlsoft.weather.util.WeatherDataUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 辐射数据 平均数据 表 服务实现类
 * </p>
 *
 * @author zhangbanglong
 * @since 2020-08-19
 */
@Service
public class RadiationAvgServiceImpl extends ServiceImpl<RadiationAvgMapper, RadiationAvg>
		implements RadiationAvgService {

	@Autowired
	private RadiationAvgMapper radiationAvgMapper;

	@Autowired
	private RadiationDataMapper radiationDataMapper;

	@Override
	public int saveAvgDay(Date dateStart, Date dateEnd) {

		int flag = 0;
		while (true) {

			Map<String, String> map = WeatherDataUtil.getYearMonDayStr(dateStart);

			String result = radiationAvgMapper.getRadiationAvgDay(map.get("year"), map.get("mon"), map.get("day"));

			List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
			RadiationAvg ga = new RadiationAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3),
					listStr.get(4), listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9),
					listStr.get(10), listStr.get(11), listStr.get(12), listStr.get(13), listStr.get(14),
					listStr.get(15));
			ga.setAvg_id(IdWorker.getIdStr());
			ga.setCreate_time(DataUtil.getCurrenTimestamp());
			ga.setData_type("day");
			ga.setYear(map.get("year"));
			ga.setMon(map.get("mon"));
			ga.setDay(map.get("day"));
			ga.setDate_time(new Timestamp(dateStart.getTime()));
			ga.setDate_str(DateUtil.DateToString(dateStart, "yyyy-MM-dd"));

			Date nextDate = WeatherDataUtil.calculateEndDate(dateStart, 1);
			if (nextDate.after(dateEnd)) {
				break;
			}
			int jflag = radiationAvgMapper.insert(ga);
			flag = flag + jflag;

			List<String> list = radiationDataMapper.getIdByYearMonDay(map.get("year"), map.get("mon"), map.get("day"));
			if (list.size() > 0) {

				Iterator<String> iter = list.iterator();
				while (iter.hasNext()) {
					String groundDataId = iter.next();

					RadiationData gd = new RadiationData();
					gd.setRadiation_data_id(groundDataId);
					gd.setAvg_flag(AvgFlagEnum.SUCCESS.getValue());
					// 更新 ground de avgFlag
					radiationDataMapper.updateById(gd);
				}
			}

			dateStart = nextDate;

		}

		// System.out.println("success 条" + flag);
		return flag;

	}

	@Override
	public int saveAvgMon(String year, String mon) {

		String result = radiationAvgMapper.getRadiationAvgMon(year, mon);

		String monStr = WeatherDataUtil.getMonMMStr(Integer.valueOf(mon));

		Date dateStart = DateUtil.StringToDate(year + "-" + monStr, "yyyy-MM");

		List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
		RadiationAvg ga = new RadiationAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3),
				listStr.get(4), listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9),
				listStr.get(10), listStr.get(11), listStr.get(12), listStr.get(13), listStr.get(14), listStr.get(15));
		ga.setAvg_id(IdWorker.getIdStr());
		ga.setCreate_time(DataUtil.getCurrenTimestamp());
		ga.setData_type(DataTypeEnum.Mon.getValue());
		ga.setYear(year);
		ga.setMon(String.valueOf(mon));
		ga.setDate_time(new Timestamp(dateStart.getTime()));
		ga.setDate_str(year + "-" + monStr);

		int jflag = radiationAvgMapper.insert(ga);

		return jflag;

	}

	@Override
	public int saveAvgYear(String yearStr) {

		int flag = 0;

		String result = radiationAvgMapper.getRadiationAvgYear(yearStr);

		Date dateStart = DateUtil.StringToDate(yearStr, "yyyy");

		List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
		RadiationAvg ga = new RadiationAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3),
				listStr.get(4), listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9),
				listStr.get(10), listStr.get(11), listStr.get(12), listStr.get(13), listStr.get(14), listStr.get(15));
		ga.setAvg_id(IdWorker.getIdStr());
		ga.setCreate_time(DataUtil.getCurrenTimestamp());
		ga.setData_type(DataTypeEnum.Year.getValue());
		ga.setYear(yearStr);
		ga.setDate_str(yearStr);
		ga.setDate_time(new Timestamp(dateStart.getTime()));

		int jflag = radiationAvgMapper.insert(ga);
		flag = flag + jflag;

		return jflag;

	}

	@Override
	public int saveAvgWeek(Date dateStart, Date dateEnd, String week) {

		Map<String, String> map = WeatherDataUtil.getYearMonDayStr(dateStart);

		String dateStartStr = DateUtil.DateToString(dateStart, "yyyy-MM-dd HH:mm:ss");
		String nextDateStr = DateUtil.DateToString(dateEnd, "yyyy-MM-dd HH:mm:ss");

		String result = radiationAvgMapper.getRadiationAvgWeek(dateStartStr, nextDateStr);

		List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
		RadiationAvg ga = new RadiationAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3),
				listStr.get(4), listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9),
				listStr.get(10), listStr.get(11), listStr.get(12), listStr.get(13), listStr.get(14), listStr.get(15));
		ga.setAvg_id(IdWorker.getIdStr());
		ga.setCreate_time(DataUtil.getCurrenTimestamp());
		ga.setData_type(DataTypeEnum.Week.getValue());
		ga.setYear(map.get("year"));
		ga.setMon(map.get("mon"));
		ga.setDate_time(new Timestamp(dateStart.getTime()));
		ga.setDate_week(week);

		int jflag = radiationAvgMapper.insert(ga);

		return jflag;

	}

	public Map<String, Object> getMapByFilesDayMonWeekYear(DataAvgDto groundAvgDto) {
		Map<String, Object> map = new HashMap<String, Object>();
		DataAvgDto dto = groundAvgDto;
		QueryWrapper<RadiationAvg> query = Wrappers.query();

		if (StringUtils.isNotBlank(dto.getV14311())) {
			query.select(dto.getV14311());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14312())) {
			query.select(dto.getV14312());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14313())) {
			query.select(dto.getV14313());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14314())) {
			query.select(dto.getV14314());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14316())) {
			query.select(dto.getV14316());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14320())) {
			query.select(dto.getV14320());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getQra_max())) {
			query.select(dto.getQra_max());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14308())) {
			query.select(dto.getV14308());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getNra_max())) {
			query.select(dto.getNra_max());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getNra_min())) {
			query.select(dto.getNra_min());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14322())) {
			query.select(dto.getV14322());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getDra_max())) {
			query.select(dto.getDra_max());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14309())) {
			query.select(dto.getV14309());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getSra_max())) {
			query.select(dto.getSra_max());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14306())) {
			query.select(dto.getV14306());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getRra_max())) {
			query.select(dto.getRra_max());
			query.orderByAsc("date_time");
			List<Object> list = radiationAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		map.put("success", false);
		map.put("message", "后台 未接收 到 需要查询的字段 参数");
		return map;
	}

	@Override
	public Map<String, Object> getRadiationAvgByFiled(DataAvgDto dataAvgDto) {

		Map<String, Object> map = new HashMap<String, Object>();
		DataAvgDto dto = dataAvgDto;
		QueryWrapper<RadiationAvg> query = Wrappers.query();

		// 处理地面数据 不同的数据类型 从不同的表中取

		// 展示的数据 类型
		if (StringUtils.isNotBlank(dto.getHour())) {
			query.eq("data_type", DataTypeEnum.Hour.getValue());

			if (StringUtils.isNotBlank(dto.getDay_who_year())) {

				Map<String, Object> map1 = this.getRadiationDataHourByFiled(dto, dto.getDay_who_year());
				if (map1 != null) {
					map.put("success", true);
					map.put("times", map1.get("times"));
					map.put("datas", map1.get("datas"));
				} else {
					map.put("success", false);
					map.put("message", "后台 未接收 到 需要查询的字段 参数");
				}
				return map;
			} else {
				map.put("success", false);
				map.put("message", "查询日平均数据类型,后台没有接收到 查询年份参数");
				return map;
			}

		} else if (StringUtils.isNotBlank(dto.getDay())) {
			query.eq("data_type", DataTypeEnum.Day.getValue());

			if (StringUtils.isNotBlank(dto.getDay_who_year())) {
				query.eq("year", dto.getDay_who_year());
				// 升序排列
				List<String> listDate = radiationAvgMapper.getDayTimeStr(DataTypeEnum.Day.getValue(),
						dto.getDay_who_year());

				// 处理各种属性 查询
				Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
				if (map1 != null) {
					map.put("success", true);
					map.put("times", listDate);
					map.put("datas", map1.get("datas"));
				} else {
					map.put("success", false);
				}
				return map;

			} else {
				map.put("success", false);
				map.put("message", "查询日平均数据类型,后台没有接收到 查询年份参数");
				return map;
			}

		} else if (StringUtils.isNotBlank(dto.getWeek())) {
			// 统计 周平均数据的 处理
			query.eq("data_type", DataTypeEnum.Week.getValue());

			if (StringUtils.isNotBlank(dto.getDay_who_year())) {
				query.eq("year", dto.getDay_who_year());
				// 升序排列
				List<String> listDate = radiationAvgMapper.getWeekTimeStr(DataTypeEnum.Week.getValue(),
						dto.getDay_who_year());

				// 处理各种属性 查询
				Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
				if (map1 != null) {
					map.put("success", true);
					map.put("times", listDate);
					map.put("datas", map1.get("datas"));
				} else {
					map.put("success", false);
				}
				return map;

			} else {
				map.put("success", false);
				map.put("message", "查询 周平均数据类型, 后台没有接收到 查询年份参数");
				return map;
			}

		} else if (StringUtils.isNotBlank(dto.getMon())) {
			// 统计 月平均数据的 处理 月平均数据 展示所有的数据
			query.eq("data_type", DataTypeEnum.Mon.getValue());
			// 获取时间轴数据
			List<String> listDateMon = radiationAvgMapper.getMonTimeStr(DataTypeEnum.Mon.getValue());
			// 处理各种属性 查询
			Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
			if (map1 != null) {
				map.put("success", true);
				map.put("times", listDateMon);
				map.put("datas", map1.get("datas"));
			} else {
				map.put("success", false);
			}
			return map;

		} else if (StringUtils.isNotBlank(dto.getYear())) {

			// 统计 年平均数据的 处理 月平均数据 展示所有的数据
			query.eq("data_type", DataTypeEnum.Year.getValue());

			// 获取时间轴数据
			List<String> listDateYear = radiationAvgMapper.getYearTimeStr(DataTypeEnum.Year.getValue());
			// 处理各种属性 查询
			Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
			if (map1 != null) {
				map.put("success", true);
				map.put("times", listDateYear);
				map.put("datas", map1.get("datas"));
			} else {
				map.put("success", false);
			}
			return map;

		} else {
			map.put("success", false);
			map.put("message", "查询地面  数据类型,后台没有接收到   统计何种(小时数据、日平均、月平均、年平均)  数据的 参数");
			return map;
		}
	}

	@Override
	public Map<String, Object> getRadiationDataHourByFiled(DataAvgDto dataAvgDto, String yearStr) {
		Map<String, Object> map = new HashMap<String, Object>();
		DataAvgDto dto = dataAvgDto;
		QueryWrapper<RadiationData> query = Wrappers.query();

		QueryWrapper<RadiationData> queryTime = Wrappers.query();
		if (StringUtils.isNotBlank(dto.getV14311())) {
			query.select(dto.getV14311());
			query.gt(dto.getV14311(), 0.0); // 大于0.0
			query.ne(dto.getV14311(), 999998.0000);
			query.ne(dto.getV14311(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14311(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14311(), 999998.0000);
			queryTime.ne(dto.getV14311(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14312())) {
			query.select(dto.getV14312());
			query.gt(dto.getV14312(), 0.0); // 大于0.0
			query.ne(dto.getV14312(), 999998.0000);
			query.ne(dto.getV14312(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14312(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14312(), 999998.0000);
			queryTime.ne(dto.getV14312(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14313())) {
			query.select(dto.getV14313());
			query.gt(dto.getV14313(), 0.0); // 大于0.0
			query.ne(dto.getV14313(), 999998.0000);
			query.ne(dto.getV14313(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14313(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14313(), 999998.0000);
			queryTime.ne(dto.getV14313(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14314())) {
			query.select(dto.getV14314());
			query.gt(dto.getV14314(), 0.0); // 大于0.0
			query.ne(dto.getV14314(), 999998.0000);
			query.ne(dto.getV14314(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14314(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14314(), 999998.0000);
			queryTime.ne(dto.getV14314(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14314())) {
			query.select(dto.getV14314());
			query.gt(dto.getV14314(), 0.0); // 大于0.0
			query.ne(dto.getV14314(), 999998.0000);
			query.ne(dto.getV14314(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14314(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14314(), 999998.0000);
			queryTime.ne(dto.getV14314(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getV14316())) {
			query.select(dto.getV14316());
			query.gt(dto.getV14316(), 0.0); // 大于0.0
			query.ne(dto.getV14316(), 999998.0000);
			query.ne(dto.getV14316(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14316(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14316(), 999998.0000);
			queryTime.ne(dto.getV14316(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14320())) {
			query.select(dto.getV14320());
			query.gt(dto.getV14320(), 0.0); // 大于0.0
			query.ne(dto.getV14320(), 999998.0000);
			query.ne(dto.getV14320(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14320(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14320(), 999998.0000);
			queryTime.ne(dto.getV14320(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getQra_max())) {
			query.select(dto.getQra_max());
			query.gt(dto.getQra_max(), 0.0); // 大于0.0
			query.ne(dto.getQra_max(), 999998.0000);
			query.ne(dto.getQra_max(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getQra_max(), 0.0); // 大于0.0
			queryTime.ne(dto.getQra_max(), 999998.0000);
			queryTime.ne(dto.getQra_max(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14308())) {
			query.select(dto.getV14308());
			query.gt(dto.getV14308(), 0.0); // 大于0.0
			query.ne(dto.getV14308(), 999998.0000);
			query.ne(dto.getV14308(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14308(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14308(), 999998.0000);
			queryTime.ne(dto.getV14308(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getNra_max())) {
			query.select(dto.getNra_max());
			query.gt(dto.getNra_max(), 0.0); // 大于0.0
			query.ne(dto.getNra_max(), 999998.0000);
			query.ne(dto.getNra_max(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getNra_max(), 0.0); // 大于0.0
			queryTime.ne(dto.getNra_max(), 999998.0000);
			queryTime.ne(dto.getNra_max(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getNra_min())) {
			query.select(dto.getNra_min());
			query.gt(dto.getNra_min(), 0.0); // 大于0.0
			query.ne(dto.getNra_min(), 999998.0000);
			query.ne(dto.getNra_min(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getNra_min(), 0.0); // 大于0.0
			queryTime.ne(dto.getNra_min(), 999998.0000);
			queryTime.ne(dto.getNra_min(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14322())) {
			query.select(dto.getV14322());
			query.gt(dto.getV14322(), 0.0); // 大于0.0
			query.ne(dto.getV14322(), 999998.0000);
			query.ne(dto.getV14322(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14322(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14322(), 999998.0000);
			queryTime.ne(dto.getV14322(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getDra_max())) {
			query.select(dto.getDra_max());
			query.gt(dto.getDra_max(), 0.0); // 大于0.0
			query.ne(dto.getDra_max(), 999998.0000);
			query.ne(dto.getDra_max(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getDra_max(), 0.0); // 大于0.0
			queryTime.ne(dto.getDra_max(), 999998.0000);
			queryTime.ne(dto.getDra_max(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14309())) {
			query.select(dto.getV14309());
			query.gt(dto.getV14309(), 0.0); // 大于0.0
			query.ne(dto.getV14309(), 999998.0000);
			query.ne(dto.getV14309(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14309(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14309(), 999998.0000);
			queryTime.ne(dto.getV14309(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getSra_max())) {
			query.select(dto.getSra_max());
			query.gt(dto.getSra_max(), 0.0); // 大于0.0
			query.ne(dto.getSra_max(), 999998.0000);
			query.ne(dto.getSra_max(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getSra_max(), 0.0); // 大于0.0
			queryTime.ne(dto.getSra_max(), 999998.0000);
			queryTime.ne(dto.getSra_max(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getV14306())) {
			query.select(dto.getV14306());
			query.gt(dto.getV14306(), 0.0); // 大于0.0
			query.ne(dto.getV14306(), 999998.0000);
			query.ne(dto.getV14306(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getV14306(), 0.0); // 大于0.0
			queryTime.ne(dto.getV14306(), 999998.0000);
			queryTime.ne(dto.getV14306(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getRra_max())) {
			query.select(dto.getRra_max());
			query.gt(dto.getRra_max(), 0.0); // 大于0.0
			query.ne(dto.getRra_max(), 999998.0000);
			query.ne(dto.getRra_max(), 999999.0000);
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = radiationDataMapper.selectObjs(query);

			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getRra_max(), 0.0); // 大于0.0
			queryTime.ne(dto.getRra_max(), 999998.0000);
			queryTime.ne(dto.getRra_max(), 999999.0000);
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = radiationDataMapper.selectObjs(queryTime);

			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		return null;
	}

	@Override
	public Map<String, Object> getNextWeekMessage() {

		Map<String, Object> map=new HashMap<String,Object>();
		
		RadiationAvg ga=radiationAvgMapper.getRadiationAvgByDataType(DataTypeEnum.Week.getValue());
		
		if( ga !=null){
			
			String beforWeek=ga.getDate_week();
			String week="";
			
			String year=ga.getYear();
			String nestYear=Integer.valueOf(year)+1+""+"-01-01 00:00:00";
			Date nextYearStartDate=DateUtil.StringToDate(nestYear, "yyyy-MM-dd HH:mm:ss");
			
			Date startDate=WeatherDataUtil.calculateEndDate(new Date(ga.getDate_time().getTime()), 7);
			Date endDate=WeatherDataUtil.calculateEndDate(startDate, 7);
			
			//如果 日期跨年   下一个 开始日期  为下一年的   开始日期
			if(startDate.after(nextYearStartDate) || endDate.after(nextYearStartDate)){
				map.put("success", true);
				 startDate=nextYearStartDate;
				 endDate=WeatherDataUtil.calculateEndDate(startDate, 7);
				 beforWeek="第0周";
			}
			
			//探测  是否存在 下一个 周期的统计数据
			List<String> list=radiationDataMapper.getIdByDataTime(DateUtil.DateToString(startDate, "yyyy-MM-dd HH:mm:ss"));
			if(list.size() >=7){
				 
				String weekStr=beforWeek.substring(beforWeek.indexOf("第")+1, beforWeek.indexOf("周"));
				int nextWeek=Integer.valueOf(weekStr)+1;
				week="第"+nextWeek+"周";
				map.put("success",true);
				map.put("message", "有满足条件的统计数据");
				map.put("startDate", startDate);
				map.put("endDate", endDate);
				map.put("whatWeek",week);
				return map;
				
			}else{
				map.put("success", false);
				map.put("message", "没有满足一周的统计数据,需等待 元数据产生");
				return map;
			}
		}else{
			Date startDate=DateUtil.StringToDate("2015-08-24 00:00:00", "yyyy-MM-dd HH:mm:ss");
			Date endDate=DateUtil.StringToDate("2015-08-30 00:00:00", "yyyy-MM-dd HH:mm:ss");
			// 需要 重头开始统计数据 
			map.put("success",true);
			map.put("message", "从 2015-08-24开始统计数据");
			map.put("startDate", startDate);
			map.put("endDate", endDate);
			map.put("whatWeek","第1周");
			return map;
		}
		
		
	}

	@Override
	public Map<String, Object> getNextMonMessage() {
		Map<String, Object> map=new HashMap<String,Object>();
		RadiationAvg ga=radiationAvgMapper.getRadiationAvgByDataType(DataTypeEnum.Mon.getValue());
		
		if( ga !=null){
			//上次 日期的 年月
			String year=ga.getYear();
			String mon=ga.getMon();
			int monInt=Integer.valueOf(mon);
			int yearInt=Integer.valueOf(year);
			
			
			//查询  两个月后的日期
			Date towDate=WeatherDataUtil.calculateEndDate(new Date(ga.getDate_time().getTime()), 63);
			
			
			
			//探测  两个月 后  是否 存在 统计数据
			List<String> list=radiationDataMapper.getIdByDataTime(DateUtil.DateToString(towDate, "yyyy-MM-dd HH:mm:ss"));
			if(list.size() >0){
				
				mon=monInt+1+"";
				
				if(monInt == 12){
					mon="1";
					year=yearInt+1+"";
				}
				
				
				map.put("success",true);
				map.put("message", "有满足条件的统计数据");
				map.put("year", year);
				map.put("mon", mon);
				return map;
				
			}else{
				map.put("success", false);
				map.put("message", "没有满足 下月 的统计数据,需等待 元数据产生");
				return map;
			}
		}else{
			// 需要 重头开始统计数据 
			map.put("success",true);
			map.put("message", "从 2015-08-24 开始统计数据");
			map.put("year", "2015");
			map.put("mon", "9");
			return map;
		}
		
	}

	@Override
	public Map<String, Object> getNextYearMessage() {
		Map<String, Object> map=new HashMap<String,Object>();
		RadiationAvg ga=radiationAvgMapper.getRadiationAvgByDataType(DataTypeEnum.Year.getValue());
		
		if( ga !=null){
			//上次 日期的 年月
			String year=ga.getYear();
			int yearInt=Integer.valueOf(year);
			
			//查询  下一年后的日期
			Date nextYearDate=WeatherDataUtil.calculateEndDate(new Date(ga.getDate_time().getTime()), 733);
			
			
			//探测  两个月 后  是否 存在 统计数据
			List<String> list=radiationDataMapper.getIdByDataTime(DateUtil.DateToString(nextYearDate, "yyyy-MM-dd HH:mm:ss"));
			if(list.size() >0){
				
				year=yearInt+1+"";
				
				map.put("success",true);
				map.put("message", "有满足条件的统计数据");
				map.put("year", year);
				return map;
				
			}else{
				map.put("success", false);
				map.put("message", "没有满足 下一年  的统计数据,需等待 元数据产生");
				return map;
			}
		}else{
			// 需要 重头开始统计数据 
			map.put("success",true);
			map.put("message", "从 2016年 开始统计 年平均数据");
			map.put("year", "2016");
			return map;
		}
		
	}

}
